package com.dm0858.bianmin.mine.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import android.os.Bundle;
import android.view.View;

import com.dm0858.bianmin.R;
import com.dm0858.bianmin.databinding.ActivityProxyLayoutBinding;
import com.dm0858.bianmin.mine.base.BaseActivity;
import com.dm0858.bianmin.mine.listener.IResultListener;
import com.dm0858.bianmin.mine.model.MineModel;
import com.dm0858.bianmin.mine.network.Retrofit;
import com.dm0858.bianmin.mine.tools.ShapeUtils;
import com.dm0858.bianmin.mine.tools.ToastUtils;

/**
 * @description 做代理
 * @author 迪迪丶Sir
 * @e-mail asd969709719@qq.com
 * @since 2020-05-02
 **/
public class ProxyActivity extends BaseActivity implements View.OnClickListener{

    private ActivityProxyLayoutBinding binding;

    private Retrofit retrofit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this,R.layout.activity_proxy_layout);
        binding.setOnClick(this);
        //按钮样式
        binding.btnCommit.setBackground(new ShapeUtils().corner(2).fill(getResources().getColor(R.color.appTheme,null)).build());
        initData();
    }

    @Override
    protected void initData() {
        if (retrofit == null) retrofit = new Retrofit();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                onBackPressed();
                break;
            case R.id.btn_commit:
                if (binding.edtName.getText().toString().equals("")) {
                    ToastUtils.showShort("姓名不能为空");
                    return;
                }
                if (binding.edtPhone.getText().toString().equals("")) {
                    ToastUtils.showShort("手机号不能为空");
                    return;
                }
                if (binding.edtIdCard.getText().toString().equals("")) {
                    ToastUtils.showShort("身份证号不能为空");
                    return;
                }
                if (binding.edtArea.getText().toString().equals("")) {
                    ToastUtils.showShort("申请地区不能为空");
                    return;
                }
                MineModel.applyAgent(retrofit,
                        binding.edtName.getText().toString(),
                        binding.edtPhone.getText().toString(),
                        binding.edtIdCard.getText().toString(),
                        binding.edtArea.getText().toString(), object -> {
                    ToastUtils.showShort("申请成功,请等待审核");
                    onBackPressed();
                });
                break;
        }
    }
}